var t = getApp();

Page({
    data: {
        selected: 0,
        commodityTitle: "",
        classificationHide: !0,
        catelist: [],
        catelistData: [],
        cateid: "",
        lastindex: 0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        loading: !1,
        goodsData: [],
        showList: !0,
        micro_style_type: 0,
        handleTag: !1
    },
    onLoad: function(t) {
        t.searchdata && this.setData({
            commodityTitle: t.searchdata
        }), t.cateId && (this.data.cateid = t.cateId), console.log(t), t.micro_style_type && this.setData({
            micro_style_type: t.micro_style_type
        }), this.classificationLabel();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {},
    classificationHideBtn: function() {
        this.setData({
            classificationHide: !0
        });
    },
    classificationLabel: function() {
        var a = this, i = t.getNetAddresss("plugin.micro-communities.api.index.getCate");
        t._getNetWork({
            url: i,
            success: function(t) {
                var i = t.data;
                if (1 == i.result) {
                    if (i.data.data.unshift({
                        child: [],
                        icon: "",
                        id: "",
                        level: 1,
                        name: "全部"
                    }), a.setData({
                        catelist: i.data.data
                    }), a.data.catelist && a.data.catelist.length > 0) {
                        for (var e = a.data.catelistData, s = 0; s < a.data.catelist.length; s++) e.push([]);
                        if (a.setData({
                            catelistData: e
                        }), a.data.cateid) {
                            for (var o = 0; o < a.data.catelist.length; o++) if (a.data.catelist[o].id == a.data.cateid) {
                                a.getClassification(!0, o), a.setData({
                                    selected: o,
                                    lastindex: o
                                });
                                break;
                            }
                        } else a.setData({
                            cateid: a.data.catelist[0].id
                        }), a.getClassification(!1);
                    }
                } else wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getClassification: function(a, i) {
        var e = this, s = {};
        e.pageInit(), this.setData({
            showList: !1
        });
        var o = t.getNetAddresss("plugin.micro-communities.api.index.getStick");
        this.data.commodityTitle && (s.title = this.data.commodityTitle), this.data.cateid && (s.cat_id = this.data.cateid), 
        t._postNetWork({
            url: o,
            showToastIn: !1,
            data: s,
            success: function(t) {
                var a = t.data;
                if (1 == a.result) return e.data.total_page = a.data.last_page, a.data.micro_style_type && e.setData({
                    micro_style_type: a.data.micro_style_type
                }), (a.data.current_page >= a.data.last_page || a.data.data.length < a.data.per_page) && (e.isLoadMore = !1), 
                e.setData({
                    goodsData: a.data.data,
                    showList: !0
                }), void console.log(e.data.goodsData);
                wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    commodityTitleClear: function() {
        this.setData({
            commodityTitle: ""
        });
    },
    commodityTitleInp: function(t) {
        var a = t.detail.value;
        this.setData({
            commodityTitle: a
        });
    },
    searchBtn: function() {
        this.setData({
            handleTag: !0
        }), this.getClassification(!0, this.data.lastindex);
    },
    swishTabTItem: function(t) {
        var a = t.detail.index, i = this.data.catelist[a].id;
        this.setData({
            selected: a,
            lastindex: a,
            cateid: i,
            handleTag: !0
        }), this.getClassification(!0, a), this.setData({
            classificationHide: !0
        });
    },
    swishTabTItemChild: function(t) {
        var a = t.currentTarget.dataset, i = a.index, e = a.id;
        this.setData({
            selected: i,
            lastindex: i,
            cateid: e,
            handleTag: !0
        }), this.getClassification(!0, i), this.setData({
            classificationHide: !0
        });
    },
    classificationShow: function() {
        this.setData({
            classificationHide: !this.data.classificationHide
        });
    },
    jumpDetails: function(t) {
        var a = t.currentTarget.dataset.stickid;
        wx.navigateTo({
            url: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + a
        });
    },
    pageInit: function() {
        this.data.page = 1, this.data.total_page = 0, this.data.isLoadMore = !0, this.data.loading = !1;
    },
    getMoreData: function() {
        var a = this, i = {};
        if (this.data.commodityTitle && (i.title = this.data.commodityTitle), this.data.cateid && (i.cat_id = this.data.cateid), 
        this.data.page >= this.data.total_page || this.data.loading) return !1;
        var e = t.getNetAddresss("plugin.micro-communities.api.index.getStick");
        a.setData({
            loading: !0
        }), a.data.page = this.data.page + 1, i.page = this.data.page, t._postNetWork({
            url: e,
            showToastIn: !1,
            data: i,
            success: function(t) {
                var i = t.data;
                if (a.setData({
                    loading: !1
                }), 1 != i.result) return a.data.page = a.data.page - 1, void (a.data.isLoadMore = !1);
                var e = i.data.data;
                a.setData({
                    goodsData: a.data.goodsData.concat(e),
                    handleTag: !1
                }), (i.data.current_page >= i.data.last_page || e.length < i.data.per_page) && (a.isLoadMore = !1);
            },
            fail: function(t) {}
        });
    }
});